package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerAppTypeDao;
import com.ctg.itrdc.imageconsole.data.dto.DockerAppTypeDTO;
import com.ctg.itrdc.imageconsole.data.entity.DockerAppType;
import com.ctg.itrdc.paspsdk.common.entity.PageInfo;
import com.ctg.itrdc.paspsdk.common.utils.type.StringUtils;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;
import com.ctg.itrdc.paspsdk.data.entity.ClassInfoUtils;

@Component("dockerAppTypeDao")
public class DockerAppTypeDaoImpl extends BaseDaoImpl implements IDockerAppTypeDao{
	
	@Override
	public PageInfo<DockerAppTypeDTO> jdbcFindPageInfo(DockerAppTypeDTO dockerAppTypeDTO, Integer currentPage,
			Integer perPageNum) {
		StringBuilder sql = this.basicSql();
		List<Object> params = new ArrayList<Object>();
		
		if(!StringUtils.isNullOrEmpty(dockerAppTypeDTO.getAppName())) {
			sql.append(" AND APP_NAME LIKE ? ");
			params.add("%" + dockerAppTypeDTO.getAppName() + "%");
		}
		
		/*if(!StringUtils.isNullOrEmpty(dockerAppTypeDTO.getTenantId())) {
			sql.append(" AND TENANT_CODE = ? ");
			params.add(dockerAppTypeDTO.getTenantId());
		}*/
		
		return this.jdbcFindPageInfo(sql.toString(), DockerAppTypeDTO.class, params, currentPage, perPageNum);
	}
	
	private StringBuilder basicSql() {
		StringBuilder sql = new StringBuilder(" SELECT ");
		String columnsName = ClassInfoUtils.getColumnsName(DockerAppType.class);
		String tableName = ClassInfoUtils.getTableName(DockerAppType.class);
		sql.append(columnsName).append(" FROM ").append(tableName).append(" WHERE 1=1 ");
		return sql;
	}

	@Override
	public List<DockerAppType> findByIdStr(String idStr) {
		String sql = "SELECT * FROM DOCKER_APP_TYPE WHERE ID IN ?";
		Object[] params = new Object[]{idStr};
		return super.getJdbcTemplate().queryForList(sql, params, DockerAppType.class);
	}

}
